home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Format CD 22
/
Amiga Format AFCD22 (Jan 1998, Issue 106).iso
/
-readerstuff-
/
d_keletsekis
/
tools
/
calc.gc
next >
Wrap
Text File
|
1997-10-03
|
7KB
|
290 lines
G4C
; calc.gc
; A calculator, which uses ARexx to calculate & display the results.
; NOTE : ** means "to the power of" i.e. 5**2 = 25
; Other ARexx operators can be entered manually if needed.
WINBIG 400 24 160 128 "RexxCalc" ; Our window.
WinType 11110001 ; It has all standard gadgets & bottom resize
WINBACKGROUND PATTERN 0 2 ; Add a flashy background..
varpath '' ; use only private variables
BOX 0 0 0 0 IN ICONDROP ; A window sized box, taking us way beyond mere "cool"
;************************** GENERAL EVENTS ***********************************
xONLOAD ; Upon loading of the GUI
ifexists port AREXX ; check for rexxmast
;
elseifexists file rexxmast
run rexxmast
elseifexists file sys:system/rexxmast
run sys:system/rexxmast
else
ezreq "Could not find RexxMast" Abort ''
guiquit calc.gc
stop
endif
setscreen calc.gc $*SCREEN
calc.var = "" ; This is our main variable
setgad calc.gc 2 HIDE ; hide the ticker tape
GUIOPEN calc.gc
setvar mem .mem1 ; These are the Memory variables
setvar .mem1 0 ; The ones starting with a full stop,
setvar .mem2 0 ; are env: variables
setvar .mem3 0
setvar .mem4 0
setvar .mem5 0
setvar membuff ""
setvar .result "0" ; somewhere to put the result (env: variable)
setvar calcmode SMALL ; small/big window
xonclose
guiquit calc.gc
xOnQuit ; On quitting we delete the env variables,
delete env:.mem#? ; so they don't linger in Env:
delvar .result
;***************************** BUTTONS GALORE ! ******************************
; All these buttons do the same thing. They AppVar their number or letter
; to our main variable and redisplay it
;=======================> The Buttons for the plain numbers
xBUTTON 10 25 25 15 1
gadkey 1 ; Keyboard shortcut
AppVar calc.var 1 ; AppVar the number to "calc.var"
update calc.gc 1 $calc.var ; and re-display it.
xBUTTON 36 25 25 15 2 ; same as above
gadkey 2
AppVar calc.var 2
update calc.gc 1 $calc.var
xBUTTON 62 25 25 15 3
gadkey 3
AppVar calc.var 3
update calc.gc 1 $calc.var
xBUTTON 10 41 25 15 4
gadkey 4
AppVar calc.var 4
update calc.gc 1 $calc.var
xBUTTON 36 41 25 15 5
gadkey 5
AppVar calc.var 5
update calc.gc 1 $calc.var
xBUTTON 62 41 25 15 6
gadkey 6
AppVar calc.var 6
update calc.gc 1 $calc.var
xBUTTON 10 57 25 15 7
gadkey 7
AppVar calc.var 7
update calc.gc 1 $calc.var
xBUTTON 36 57 25 15 8
gadkey 8
AppVar calc.var 8
update calc.gc 1 $calc.var
xBUTTON 62 57 25 15 9
gadkey 9
AppVar calc.var 9
update calc.gc 1 $calc.var
xBUTTON 10 73 25 15 0
gadkey 0
AppVar calc.var 0
update calc.gc 1 $calc.var
xBUTTON 36 73 25 15 .
gadkey .
AppVar calc.var .
update calc.gc 1 $calc.var
xBUTTON 62 73 25 15 < ; backspace
gadkey #8
cutvar calc.var CUT CHAR -1 "" ; It will delete the last character of
update calc.gc 1 $calc.var ; "calc.var" and re-display it
;=========================> The operators
xBUTTON 90 25 25 15 /
gadkey /
AppVar calc.var /
update calc.gc 1 $calc.var
xBUTTON 90 41 25 15 * ; hit twice for square
gadkey *
AppVar calc.var *
update calc.gc 1 $calc.var
xBUTTON 90 57 25 15 -
gadkey -
AppVar calc.var -
update calc.gc 1 $calc.var
xBUTTON 90 73 25 15 +
gadkey +
AppVar calc.var +
update calc.gc 1 $calc.var
;------------- right most bank
xBUTTON 116 25 35 15 (
gadkey (
AppVar calc.var (
update calc.gc 1 $calc.var
xBUTTON 116 41 35 15 )
gadkey )
AppVar calc.var )
update calc.gc 1 $calc.var
xBUTTON 116 57 35 15 CLR ; Clear
gadkey #127
update calc.gc 1 0
setvar calc.var ""
if $calcmode = BIG ; update ticker tape
lvuse calc.gc 2
LVAdd '** Clear **'
endif
xBUTTON 116 73 35 15 =
gadkey #13
gosub calc.gc calculate ; GoSub the routine which does the calculation
;===========================> This is our display panel. - Note it's
; a xTEXTin type gadget, so we can enter a calculation directly into it.
xTEXTIN 10 5 140 18 "" calc.var 0 512
GADID 1
gosub calc.gc calculate ; GoSub the routine which does the calculation
;===================> routine to calculate & display result
xROUTINE calculate
lvuse calc.gc 2 ; use ticker tape lv
if $calc.var > "" ; If there is an entry
if $calcmode = BIG
LVAdd '$calc.var'
endif
cli "rx 'say >env:.result $calc.var'"
update calc.gc 1 $.result ; and display the answer EVAL returned
setvar calc.var $.result ; We set "calc.var" to the result
if $calcmode = BIG ; update ticker tape
LVAdd "-> $calc.var"
endif
if $calc.var = 0
calc.var = "" ; and if it's 0, we empty it (looks nicer)
endif
endif
;***************************** MEMORIES **************************************
; If you look at the following code carefully, you will see that we
; need a variable within a variable.
; We use "membuff" to construct such a variable.
;=======================> Memories display panel
xTEXTIN 10 90 140 16 "" $mem 0 30
GadID 5
;=======================> Memories cycler
xCycler 10 108 60 15 "" mem
Cstr "M1" .mem1
Cstr "M2" .mem2
Cstr "M3" .mem3
Cstr "M4" .mem4
Cstr "M5" .mem5
setvar membuff "\$$mem" ; This means set membuff to $ + whatever is in "mem"
update calc.gc 5 $membuff ; so that it points to the correct variable
;=======================> Memory IN/OUT
xButton 70 108 20 15 I ; These buttons do the usual MEM in/out/+/-
SetVar $mem $calc.var ; stuff that calculators do.
setvar membuff "\$$mem"
update calc.gc 5 $membuff
xButton 90 108 20 15 O
setvar membuff "\$$mem"
AppVar calc.var $membuff
update calc.gc 1 $calc.var
xButton 110 108 20 15 +
setvar membuff "\$$mem"
cli "rx 'say >env:$mem $calc.var + $membuff'"
setvar membuff "\$$mem"
update calc.gc 5 $membuff
xButton 130 108 20 15 -
setvar membuff "\$$mem"
cli "rx 'say >env:$mem $membuff - $calc.var'"
setvar membuff "\$$mem"
update calc.gc 5 $membuff
;***************************** Ticker Tape **********************************
; Here we expand the window to include a listview for the ticker tape
; This is done on clicking of the Right Mouse Button
xOnRMB
if $calcmode = SMALL
calcmode = BIG
changegad calc.gc 0 -1 -1 320 128 ""
setgad calc.gc 2 SHOW
else
calcmode = SMALL
lvuse calc.gc 2
lvclear
changegad calc.gc 0 -1 -1 160 128 ""
setgad calc.gc 2 HIDE
endif
redraw calc.gc
;---- This is the listview that will show the results
; update main calc pannel according to lv line clicked
xListview 155 5 158 123 "" calc.lv "" 10 TXT
gadid 2
cutvar calc.lv copy char 3 calc.3 ; update display to line content
if $calc.3 = '** ' ; clear line
calc.var = 0
else
if $calc.3 = '=> ' ; a result
cutvar calc.lv cut char 3 ""
calc.var = $calc.lv
else
calc.var = $calc.lv ; a calculation
endif
endif
update calc.gc 1 $calc.var
if $calc.var = 0
calc.var = ''
endif